package com.accenture.adf.newcodington.module12.sample;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * 
 * Topic: Demo on using the Set data type from the Java collection framework
 * 
 * Instructions:
 * 1. Create a 'SetDemo' class
 * 2. Create a main() method that will perform the following functions
 *    a. Create a Set using the HashSet constructor
 *    b. Populate the Set with several elements and print the return value of the add() method
 *       i. The method returns true if the element was successfully added or returns false if
 *          a duplicate is attempted to be added
 *    c. Print all the elements of the Set
 *    
 */

public class SetDemo {
	
	public static void main(String[] args) {
		
		// Creating Set object using HashSet implementation
		Set<String> placeSet = new HashSet<String>();

		//duplicates will return false
		System.out.println(placeSet.add("Zoo"));
		System.out.println(placeSet.add("Park"));
		System.out.println(placeSet.add("Museum")); 
		System.out.println(placeSet.add("Zoo"));
		System.out.println(placeSet.add("Stadium"));

		System.out.println("Output for Set Collection : ");

		// Using ITERATOR for displaying all elements in SET collection
		for(Iterator<String> iterator=placeSet.iterator();iterator.hasNext();)
		{
			System.out.println("Elements are :"+iterator.next());
		}
		
	}
}